﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Professer : BasePage
{
    //chuoi ket noi
    string connectionString = WebConfigurationManager.ConnectionStrings["DanhGiaGiaoVienConnectionString1"].ConnectionString;
    private SqlConnection conn = null;
    private SqlDataAdapter dataAdapter = null;
    private DataTable dataTable = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userName"] == null || Session["userType"] == null || Session["userType"].ToString() != "GiangVien")
        {
            Response.Redirect("~/Default.aspx");
        }
        else
        {
            conn = new SqlConnection(connectionString);

            string MSGV = Session["userName"].ToString();
            dataAdapter = new SqlDataAdapter("select HoTen, HocKy, TenMH,count(distinct MSSV) as TongSVDG,sum(Diem) as TongDiem,Round(Convert(Float,(sum(Diem)))/Convert(Float,(count(distinct MSSV))),2) as DiemTB from ChiTietDanhGia, MonHoc,GiangVien where ChiTietDanhGia.MSGV='" + MSGV + "' and ChiTietDanhGia.MaMH=MonHoc.MaMH and ChiTietDanhGia.MSGV=GiangVien.MSGV group by HoTen, HocKy, TenMH", conn);
            SqlCommand cmd = new SqlCommand("select distinct T.MSGV,round((convert(float,diem1)/convert(float,tong)),2)as chuatot,round((convert(float,diem2)/convert(float,tong)),2)as binhthuong,round((convert(float,diem3)/convert(float,tong)),2)as tot,round((convert(float,diem4)/convert(float,tong)),2)as rattot" +
                                           " from ChiTietDanhGia T,(select MSGV,COUNT(Diem)as diem1 from ChiTietDanhGia where diem =1 group by MSGV) as T1," +
                                                                "(select MSGV,COUNT(Diem)as diem2 from ChiTietDanhGia where diem =2 group by MSGV) as T2," +
                                                                "(select MSGV,COUNT(Diem)as diem3 from ChiTietDanhGia where diem =3 group by MSGV) as T3," +
                                                                "(select MSGV,COUNT(Diem)as diem4 from ChiTietDanhGia where diem =4 group by MSGV) as T4," +
                                                                "(select MSGV,count(*) as Tong from ChiTietDanhGia group by MSGV) as T5 where T.MSGV=T1.MSGV "+
                                                                "and T.MSGV=T2.MSGV and T.MSGV=T3.MSGV and T.MSGV = T4.MSGV and T.MSGV = T5.MSGV and T.MSGV='" + MSGV + "'", conn);

            SqlDataReader reader;
            //Khai báo và khởi tạo biến Connection 
            conn.Open();
            DataTable dataTable = new DataTable();
            dataAdapter.Fill(dataTable);
            GridView1.DataSource = dataTable;
            GridView1.DataBind();
            reader = cmd.ExecuteReader();
            GridView2.DataSource = reader;
            GridView2.DataBind();
            conn.Close();
        }
    }

    public void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        Logout();
    }
}